layui.use(['form','layer','qsform'],function(){
	var $ = layui.jquery,
			layer = parent.layer === undefined ? layui.layer : top.layer,
			form = layui.form,
			qsform = layui.qsform;
	
    form.on("submit(addRole)",function(data){
        // 弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        let _id = $(".id").val()
        let _message = "文章添加成功";
        let _formdata = qsform.getDataByQsName(data);
        console.log(_formdata);
        if(_id == null || _id == ""){
        	// 新增
            $.post("../../roles/", JSON.parse(_formdata), function(res){
           
            })
        }else{
        	// 更新
            $.ajax({
                url : "../../roles/",
                type : "PUT",
                data : JSON.parse(_formdata),
                success : function (res) {
                    
                },
                error : function (res) {
                    layer.msg("更新失败");
                    return false;
                }
            })
            _message = "用户修改成功";
        }
        setTimeout(function(){
            layer.close(index);
            layer.msg(_message);
            layer.closeAll("iframe");
            // 刷新父页面
            parent.location.reload();
        },500);
        return false;
    })
})